﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CSTest
{
    public class StringUtils
    {
        /// <summary>
        /// Format all object propertities to String
        /// </summary>
        /// <param name="obj">Object</param>
        /// <returns>String</returns>
        public static string ObjectToString(Object obj)
        {
            StringBuilder sb = new StringBuilder(obj.GetType().ToString());
            sb.Append(':');
            PropertyInfo[] ps = obj.GetType().GetProperties();
            foreach (var item in ps)
            {
                sb.AppendLine();
                try
                {
                    if (item.CanRead)
                        sb.Append("---" + item.Name + ":" + item.GetValue(obj, null).ToString());
                }
                catch (Exception ex)
                { }
            }
            sb.AppendLine();
            return sb.ToString();
        }
    }
}
